home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / dns / ddt2.0 / cmd / rmc < prev    next >
Encoding:
Text File  |  1993-06-01  |  4.2 KB  |  205 lines

  1. #! /usr/local/bin/perl
  2. #
  3. #  grc - reverse mapping checker
  4. #
  5. #  invoke as:
  6. #       rmc [-l msglevel]
  7. #
  8. #  Copyright (C) 1992, 1993 PUUG - Grupo Portugues de Utilizadores do
  9. #                   Sistema UNIX
  10. #                1992, 1993 FCCN - Fundacao para o Desenvolvimento dos Meios 
  11. #                                   Nacionais de Calculo Cientifico 
  12. #
  13. #  Authors: Jorge Frazao de Oliveira <frazao@puug.pt>
  14. #           Artur Romao <artur@dns.pt>
  15. #
  16. #  This file is part of the DDT package, Version 2.0.
  17. #
  18. #  Permission to use, copy, modify, and distribute this software and its 
  19. #  documentation for any purpose and without any fee is hereby granted, 
  20. #  provided that the above copyright notice appear in all copies.  Neither 
  21. #  PUUG nor FCCN make any representations about the suitability of this
  22. #  software for any purpose.  It is provided "as is" without express or 
  23. #  implied warranty.
  24.  
  25.  
  26. # =()<push(@INC, "@<LIBDIR>@");>()=
  27. push(@INC, "/usr/local/lib/ddt/cmd");
  28.  
  29. require "ddt.pl";
  30.  
  31.  
  32. # scan the standard input
  33. while (<STDIN>) {
  34.     next if /^;/;            # ignore commented lines
  35.  
  36.     chop;                # strip record separator    
  37.     @Field = split(/\s+/, $_);    # break the input line
  38.  
  39.     if (/^\$ORIGIN/) {
  40.         $Origin = $Field[2];    # set to a different origin
  41.     
  42.         next;
  43.         }
  44.  
  45.     if (/^[*\.\-0-9A-Za-z]+/) { 
  46.         $Name = &make_name($Field[1], $Origin);
  47.     }
  48.  
  49.     if (/\tIN\tSOA\t/) {
  50.         $Zone         = $Name;
  51.         $Zones{$Zone} = 1;
  52.  
  53.         <STDIN> if /\(\s*$/;    # skip the line defining the timers
  54.     }
  55.     elsif (/\tIN\tA/) {
  56.         &A_RR($Zone, $Name, $Field[$#Field]);
  57.     }
  58.     elsif (/\tIN\tPTR/) {
  59.         &PTR_RR($Zone, $Name, $Field[$#Field]);
  60.     }
  61. }
  62.  
  63. foreach $Zone (keys %Zones) {
  64.         &show_zone($Zone);
  65. }
  66.  
  67. exit 0;
  68.  
  69.  
  70. sub perror_rev_mapping {
  71.         local($host, $address) = @_;
  72.  
  73.     if (!$Printed{$host, $address}) {
  74.         if ($Level >= 3) {
  75.             $Printed{$host, $address} = 1;        
  76.     
  77.             $address = join(".", reverse(split(/\./, $address)));
  78.  
  79.             print "$Lpad[3]No $address.in-addr.arpa PTR RR found for $host";
  80.         }
  81.     }
  82. }
  83.  
  84.  
  85. sub perror_mapping {
  86.     local($host, $address) = @_;
  87.  
  88.         if (!$Printed{$host, $address}) {
  89.                 if ($Level >= 3) {
  90.                         $Printed{$host, $address} = 1;
  91.  
  92.             print "$Lpad[3]No $host A RR found with", 
  93.                   &arpa2ip($address);
  94.         }
  95.     }
  96. }
  97.  
  98.  
  99. #
  100. # converts an in-addr.arpa name to an IP address
  101. #
  102. sub arpa2ip {
  103.     local($revaddress) = @_;
  104.     local($first, $second, $third, $fourth);
  105.  
  106.     ($first, $second, $third, $fourth) = split(/\./, $revaddress);
  107.  
  108.     return join(".", $fourth, $third, $second, $first);
  109. }
  110.  
  111.  
  112. #
  113. # add $address to the list of addresses for $host in $zone
  114. #
  115. sub A_RR {
  116.         local($zone, $host, $address) = @_;
  117.  
  118.     $host = &tolower($host);
  119.  
  120.     $Azone{$zone} = &add_list($Azone{$zone}, 
  121.                       join($ELEMsep1, $host, $address));
  122.  
  123.     $Addresses{$host} = &add_list($Addresses{$host}, $address);
  124. }
  125.  
  126.  
  127. #
  128. # add $host to the list of hosts addressed $address in $zone
  129. #
  130. sub PTR_RR {
  131.         local($zone, $address, $host) = @_;
  132.  
  133.     $host = &tolower($host);
  134.  
  135.         $address = join(".", split(/\./, $address));
  136.  
  137.     $PTRzone{$zone} = &add_list($PTRzone{$zone},
  138.                      join($ELEMsep1, $host, $address));
  139.  
  140.         $Hosts{&arpa2ip($address)} = &add_list($Hosts{$address}, $host);
  141. }
  142.  
  143.  
  144. #
  145. # if $address "has" $host
  146. #
  147. sub rev_mapped {
  148.         local($host, $address) = @_;
  149.  
  150.     return &in($host, $Hosts{$address}, $LISTsep);
  151. }
  152.  
  153.  
  154. #
  155. # if $host has $address
  156. #
  157. sub mapped {
  158.         local($host, $address) = @_;
  159.  
  160.     return &in(&arpa2ip($address), $Addresses{$host}, $LISTsep);
  161. }
  162.  
  163.  
  164. #
  165. # for each A record check if there is the corresponding PTR
  166. # and vice-versa for PTR RR's
  167. #
  168. sub check_mapping {
  169.         local($zone) = @_; 
  170.     local(@HA, $ha);
  171.  
  172.     if (defined $Azone{$zone}) {
  173.         @HA = split($LISTsep, $Azone{$zone});
  174.  
  175.         while ($ha = shift(@HA)) {
  176.             ($host, $address) = split($ELEMsep1, $ha);
  177.  
  178.             if (!&rev_mapped($host, $address)) {
  179.                 &perror_rev_mapping($host, $address);
  180.             }
  181.         }
  182.     }
  183.  
  184.     if (defined $PTRzone{$zone}) {
  185.         @HA = split($LISTsep, $PTRzone{$zone});
  186.  
  187.                   while ($ha = shift(@HA)) {
  188.                       ($host, $address) = split($ELEMsep1, $ha);
  189.  
  190.                         if (!&mapped($host, $address)) {
  191.                                   &perror_mapping($host, $address);
  192.                         }
  193.                 }
  194.         }
  195. }
  196.  
  197.  
  198. sub show_zone {
  199.     local($zone) = @_;
  200.  
  201.     print "\n ###", &toupper($zone), "###";
  202.  
  203.     &check_mapping($zone);
  204. }
  205.